package com.example.analysis.controller;


import com.example.analysis.entity.Course;
import com.example.analysis.service.CourseService;
import com.example.analysis.utils.Response;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/course")
@CrossOrigin
public class CourseController {
    @Autowired
    private CourseService courseService;
    @PostMapping("/insert")
    public Response<Course> insert(@RequestBody Course course) {
        return courseService.insert(course);
    }

    @DeleteMapping("/delete")
    public Response<Course> deleteByCourseId(@RequestParam String courseId) {
        return courseService.deleteByCourseId(courseId);
    }

    @PutMapping("/update")
    public Response<Course> update(@RequestBody Course course) {
        return courseService.update(course);
    }

    @GetMapping("/get-by-id")
    public Response<Course> getByCourseId(@RequestParam String courseId) {
        return courseService.getById(courseId);
    }

    @GetMapping("/get-all")
    public Response<List<Course>> getAllCourses() {
        return courseService.getAllCourses();
    }
    /**
     * 查询所有课程
     * @return 课程集合/失败信息
     */
    @GetMapping("/get_all")
    public Response<List<Course>> getAll() {
        return courseService.getAll();
    }

    /**
     * 根据班级id获取课程节点集合
     * @param classId 班级id
     * @return 课程节点集合
     */
    @GetMapping("/get_course_by_class_id")
    public Response<List<Course>> getCourseData(String classId) {
        System.out.println(classId);
        return courseService.getCourseData(classId);
    }
}
